#!/bin/bash

cwd=`pwd`
YARP_SVN=https://yarp0.svn.sourceforge.net/svnroot/yarp0/trunk/yarp2
REVISION=7734
#@note: 7735 won't compile
if [ ! -e yarp ]; then
    echo Fetching YARP from SVN...
    svn co -r $REVISION $YARP_SVN yarp
else
    echo Checking for YARP updates...
    cd yarp
    svn up -r $REVISION
fi

echo Checking if YARP can be configured
mkdir -p $cwd/build
cd $cwd/build && cmake ../yarp || (
    echo "YARP cannot be configured - no ACE?"
    rm -f $cwd/build/CMakeCache.txt
    echo "Fetching ACE..."
    cd $cwd
    ./fetch-ace.sh
    cd $cwd/build && cmake -DBUILTIN_ACE:BOOL=TRUE -DBUILTIN_ACE_SOURCE_DIR:STRING=$cwd/ace4yarp/src -DBUILTIN_ACE_INCLUDE_DIR:STRING=$cwd/ace4yarp/include  ../yarp || (
	echo "YARP cannot be configured"
	test -e CMakeCache.txt && mv CMakeCache.txt CMakeCache.txt.log
	exit 1
    )
)

echo Building YARP and test program...
cd $cwd/build && cmake ../yarp && make && cd ../test && \
  cmake -DYARP_DIR=$cwd/build && make

